<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>给出一个使用 FreeType 2 字体的文本框</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.imageftbbox" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imageftbbox</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.7, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">imageftbbox</span> &mdash; <span class="dc-title">给出一个使用 FreeType 2 字体的文本框</span></p>

 </div>
  <div class="refsect1 description" id="refsect1-function.imageftbbox-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imageftbbox</strong></span>
    ( <span class="methodparam"><span class="type">float</span> <code class="parameter">$size</code></span>
   , <span class="methodparam"><span class="type">float</span> <code class="parameter">$angle</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$fontfile</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$text</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$extrainfo</code></span>
  ] ) : <span class="type">array</span></div>

  <p class="para rdfs-comment">
   This function calculates and returns the bounding box in pixels
   for a FreeType text.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imageftbbox-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">size</code></dt>

     <dd>

      <p class="para">字体的尺寸。根据 GD 的版本，为像素尺寸（GD1）或点（磅）尺寸（GD2）。</p>
     </dd>

    
    
     <dt>
<code class="parameter">angle</code></dt>

     <dd>

      <p class="para">
       Angle in degrees in which <code class="parameter">text</code> will be 
       measured.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">fontfile</code></dt>

     <dd>

      <p class="para">
       The name of the TrueType font file (can be a URL). Depending on
       which version of the GD library that PHP is using, it may attempt to
       search for files that do not begin with a leading &#039;/&#039; by appending
       &#039;.ttf&#039; to the filename and searching along a library-defined font path.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">text</code></dt>

     <dd>

      <p class="para">
       The string to be measured.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">extrainfo</code></dt>

     <dd>

      <p class="para">
       <table class="doctable table">
       <caption><strong>Possible array indexes for <code class="parameter">extrainfo</code></strong></caption>
        
         <thead>
          <tr>
           <th>Key</th>
           <th>Type</th>
           <th>Meaning</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><em>linespacing</em></td>
           <td><span class="type"><a href="language.types.float.html" class="type float">float</a></span></td>
           <td>Defines drawing linespacing</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imageftbbox-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>imageftbbox()</strong></span> returns an array with 8
   elements representing four points making the bounding box of the
   text:
   <table class="doctable informaltable">
    
     <tbody class="tbody">
      <tr>
       <td>0</td>
       <td>lower left corner, X position</td>
      </tr>

      <tr>
       <td>1</td>
       <td>lower left corner, Y position</td>
      </tr>

      <tr>
       <td>2</td>
       <td>lower right corner, X position</td>
      </tr>

      <tr>
       <td>3</td>
       <td>lower right corner, Y position</td>
      </tr>

      <tr>
       <td>4</td>
       <td>upper right corner, X position</td>
      </tr>

      <tr>
       <td>5</td>
       <td>upper right corner, Y position</td>
      </tr>

      <tr>
       <td>6</td>
       <td>upper left corner, X position</td>
      </tr>

      <tr>
       <td>7</td>
       <td>upper left corner, Y position</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   The points are relative to the <em class="emphasis">text</em> regardless of the
   <code class="parameter">angle</code>, so &quot;upper left&quot; means in the top left-hand 
   corner seeing the text horizontally.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imageftbbox-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3707">
    <p><strong>Example #1 <span class="function"><strong>imageftbbox()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;a&nbsp;300x150&nbsp;image<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">300</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">150</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$black&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$white&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Set&nbsp;the&nbsp;background&nbsp;to&nbsp;be&nbsp;white<br /></span><span style="color: #0000BB">imagefilledrectangle</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">299</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">299</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$white</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Path&nbsp;to&nbsp;our&nbsp;font&nbsp;file<br /></span><span style="color: #0000BB">$font&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'./arial.ttf'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;First&nbsp;we&nbsp;create&nbsp;our&nbsp;bounding&nbsp;box<br /></span><span style="color: #0000BB">$bbox&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imageftbbox</span><span style="color: #007700">(</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$font</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'The&nbsp;PHP&nbsp;Documentation&nbsp;Group'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;our&nbsp;cordinates&nbsp;for&nbsp;X&nbsp;and&nbsp;Y<br /></span><span style="color: #0000BB">$x&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]&nbsp;+&nbsp;(</span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">)&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;(</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">4</span><span style="color: #007700">]&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$y&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;+&nbsp;(</span><span style="color: #0000BB">imagesy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">)&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;(</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">5</span><span style="color: #007700">]&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">imagefttext</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$x</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$y</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$black</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$font</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'The&nbsp;PHP&nbsp;Documentation&nbsp;Group'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Output&nbsp;to&nbsp;browser<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type:&nbsp;image/png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.imageftbbox-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数需要 GD 2.0.1 或更高版本(推荐 2.0.28 及更高版本)。</span></p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数仅在
PHP 编译时加入 freetype 支持时有效（<strong class="option configure">--with-freetype-dir=DIR</strong>
）。</span></p></blockquote>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.imageftbbox-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>4.3.5</td>
       <td>
        <code class="parameter">extrainfo</code> was made optional.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

</div></div></div></body></html>